<?php

require_once("lib/exception/internal_error_exception.php");
require_once("lib/exception/parameters_exception.php");
require_once("lib/exception/duplicate_instance_exception.php");

require_once("lib/model/action.php");
require_once("model/autorfacade/util/util_autor.php");

require_once("model/autor/to/autor_to.php");
require_once("model/autor/dao/autor_dao_factory.php");

class Register_autor_action implements Action {

	private $autor_to;
	
	public function __construct($autor_to) {
		
		$this->autor_to = $autor_to;
	}
	
	public function do_execute() {
		try {
			$dao = Autor_dao_factory::singleton()->get_dao();
			
			$util = new Util_autor();
						
			return $dao->create(new Autor_to($this->autor_to->get_login(),
											$util->get_encrypted($this->autor_to->get_password()),
											$this->autor_to->get_email()));
		}
		catch (Internal_error_exception $e) {
			throw $e;
		}
		catch (Duplicate_instance_exception $e) {
			throw new Model_exception($e);
		}
		catch (Exception $e) {
			throw new Exception("Internal error exception --> " . $e);
		}
	}
	
}

?>